package com.yellowpage.wf.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.WorkflowDao;
import com.yellowpage.wf.dao.WorkflowInstanceDao;
import com.yellowpage.wf.dao.WorkflowNodeDao;
import com.yellowpage.wf.dao.WorkflowNodeInstanceDao;
import com.yellowpage.wf.dao.WorkflowPathDao;
import com.yellowpage.wf.dao.WorklistDao;
import com.yellowpage.wf.dao.WorkHistoryDao;
import com.yellowpage.wf.data.Workflow;
import com.yellowpage.wf.data.WorkflowDataUtils;
import com.yellowpage.wf.data.WorkflowInstance;
import com.yellowpage.wf.data.WorkflowNode;
import com.yellowpage.wf.data.WorkflowNodeInstance;
import com.yellowpage.wf.data.WorkflowPath;
import com.yellowpage.wf.data.Worklist;
import com.yellowpage.wf.data.WorkHistory;

public class WorkflowServiceImpl extends BaseServiceImpl implements WorkflowService {
	  private WorkflowDao workflowDao;
	  private WorkflowNodeDao workflowNodeDao;
	  private WorkflowPathDao workflowPathDao;
	  private WorkflowInstanceDao workflowInstanceDao;
	  private WorkflowNodeInstanceDao workflowNodeInstanceDao;
	  private WorkHistoryDao workHistoryDao;
	  private WorklistDao worklistDao;

    
    public String getWorkflowTypeByWorkListId(String listId) {
    	String sql = " select f.type from wf_workflow_node_instance w , wf_worklist l , wf_workflow f , wf_workflow_instance i where f.workflow_id = i.workflow_id and i.workflow_instance_id = w.workflow_instance_id and l.wf_workhistory_id = w.workflow_history_id and l.wf_worklist_id = " + listId;
    	
    	List<Map> list = this.baseDao.query(sql , new HashMap());
    	
    	if(list != null && list.size() > 0) return (String)list.get(0).get("TYPE");
    	
    	return null;
    }

    public List<Map> queryWorkflowByPage(Map queryMap, PageRender pageRender) {

		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				" SELECT a.WORKFLOW_ID, a.CREATE_TIME, a.LAST_UPDATE_TIME, a.NAME, a.TYPE, a.STATUS, " +
				" (select decode(e.name, null, '系统管理员',e.name) " +
				" from employee e, WF_WORKFLOW ww " +
				" where ww.create_user = e.employee_id(+) " +
				" and ww.workflow_id = a.workflow_id) as CREATE_USER, " +
				" (select decode(e.name, null, '系统管理员',e.name) " +
				" from employee e, WF_WORKFLOW ww" +
				" where ww.last_update_user = e.employee_id(+) " +
				" and ww.workflow_id = a.workflow_id) as LAST_UPDATE_USER " +
				"  FROM WF_WORKFLOW a WHERE 1=1 " )
		.addCondition(" and NAME like :name ")
		.addCondition(" and TYPE like :type ")
		.addCondition(" and STATUS like :status ");
		sqlAssistant.setTail(" ORDER BY a.WORKFLOW_ID DESC ");


		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}

	public Map findNode(Long workflowId) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.WORKFLOW_ID ,a.NAME  FROM WF_WORKFLOW a , WF_WORKFLOW_NODE c WHERE 1=1 "
						+" and  a.workflow_id=c.workflow_id "
						+" and  c.type not in ( '"+WorkflowDataUtils.NODE_TYPE_START+"','"+WorkflowDataUtils.NODE_TYPE_END+"' )"
						+" and  a.WORKFLOW_ID = "+workflowId.toString());

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(), new HashMap());

		if(resultList!=null && resultList.size()>0){
			return resultList.get(0);
		}else{
			return null;
		}
	}

       
    public void saveWorkflow(Workflow workflow) {
		workflow.setStatus(WorkflowDataUtils.ENTITY_STATUS_ON);
		workflowDao.save(workflow);

		WorkflowNode workflowNode = new WorkflowNode();
		workflowNode.setCreateTime(new Date());
		workflowNode.setCreateUser(workflow.getCreateUser());
		workflowNode.setLastUpdateTime(new Date());
		workflowNode.setLastUpdateUser(workflow.getCreateUser());
		workflowNode.setNodeStaus(WorkflowDataUtils.ENTITY_STATUS_ON);
		// 增加工作流起始节点
		workflowNode.setWorkflowId(workflow.getWorkflowId());
		workflowNode.setType(WorkflowDataUtils.NODE_TYPE_START);
		workflowNode.setName(WorkflowDataUtils.START_POINT_DISPLAYNAME);
		workflowNode.setDisplayName(WorkflowDataUtils.START_POINT_DISPLAYNAME);
		workflowNodeDao.save(workflowNode);
		// 增加工作流结束节点
		WorkflowNode workflowNodeEnd = new WorkflowNode();
		workflowNodeEnd.setWorkflowId(workflow.getWorkflowId());
		workflowNodeEnd.setType(WorkflowDataUtils.NODE_TYPE_END);
		workflowNodeEnd.setName(WorkflowDataUtils.END_POINT_DISPLAYNAME);
		workflowNodeEnd.setDisplayName(WorkflowDataUtils.END_POINT_DISPLAYNAME);
		workflowNodeDao.save(workflowNodeEnd);
	}
    
    public void saveWorkflowNode(WorkflowNode workflowNode, Long preNodeId, Long afterNodeId){
    	
    	workflowNodeDao.save(workflowNode);
    	
    	if(preNodeId != null){
			WorkflowNode preWorkflowNode = workflowNodeDao.get(preNodeId);			
			
			WorkflowPath prePath = new WorkflowPath();
			prePath.setName(preWorkflowNode.getName() + "-" + workflowNode.getName());
			prePath.setDisplayName(preWorkflowNode.getDisplayName() + "-" + workflowNode.getDisplayName());
			prePath.setWorkflowId(workflowNode.getWorkflowId());
			prePath.setNodeFrom(preNodeId);
			prePath.setNodeTo(workflowNode.getWorkflowNodeId());
			prePath.setCreateTime(new Date());
			prePath.setCreateUser(workflowNode.getCreateUser());
			prePath.setLastUpdateTime(new Date());
			prePath.setLastUpdateUser(workflowNode.getLastUpdateUser());
			
			workflowPathDao.save(prePath);
		}
		
		if(afterNodeId != null){
			WorkflowNode afterWorkflowNode = workflowNodeDao.get(afterNodeId);
			
			WorkflowPath afterPath = new WorkflowPath();
			afterPath.setName(workflowNode.getName() + "-" + afterWorkflowNode.getName());
			afterPath.setDisplayName(workflowNode.getDisplayName() + "-" + afterWorkflowNode.getDisplayName());
			afterPath.setWorkflowId(workflowNode.getWorkflowId());
			afterPath.setNodeFrom(workflowNode.getWorkflowNodeId());
			afterPath.setNodeTo(afterNodeId);
			afterPath.setCreateTime(new Date());
			afterPath.setCreateUser(workflowNode.getCreateUser());
			afterPath.setLastUpdateTime(new Date());
			afterPath.setLastUpdateUser(workflowNode.getLastUpdateUser());
			
			workflowPathDao.save(afterPath);
		}
    	
    }
    
    
	public List<Map> getWorkflowContext(Map queryMap) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.CONTEXT_ID , a.PARAM_NAME , a.PARAM_TYPE, a.DEFAULT_VALUE  FROM WF_CONTEXT a WHERE 1=1 ")
				.addCondition(" and PARAM_NAME = :paramName ").addCondition(
						" and WORKFLOW_ID = :workflowId ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				queryMap);

		return resultList;
	}	
	
	
	public List<Map> getWorkflowNodeContext(Map queryMap) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.NODE_CONTEXT_ID , a.PARAM_NAME , a.PARAM_TYPE, a.DEFAULT_VALUE  FROM WF_NODE_CONTEXT a WHERE 1=1 ")
				.addCondition(" and PARAM_NAME = :paramName ").addCondition(
						" and workflow_node_id = :workflowNodeId ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				queryMap);

		return resultList;
	}
    

	  public void updateWorkflow(Workflow workflow){
	      workflowDao.update(workflow);
	  }

	  public void delete(List deleteList){
	      workflowDao.remove(deleteList);
	  }
	  
	  public List<Map> deleteWorkflow(List<Long> deleteIdsList) {
			List cannotDeleteWorkflowMapList = new ArrayList();
//			List<Long> cannotIdsList = new ArrayList<Long>();
//			for (Long id : deleteIdsList) {
//				Map resultMap = this.findNode(id);
//				if (resultMap != null) {
//					cannotIdsList.add(Long.valueOf(resultMap.get("WORKFLOW_ID")
//							.toString()));
//					cannotDeleteWorkflowMapList.add(resultMap);
//				}
//			}
//			deleteIdsList.removeAll(cannotIdsList);
			workflowPathDao.clearByWorkflowId(deleteIdsList);
			workflowNodeDao.clearByWorkflowId(deleteIdsList);
			workflowDao.remove(deleteIdsList);
			return cannotDeleteWorkflowMapList;
		}
	  
	  public List<Map> deleteWorkflowNode(List<Long> deleteNodeIdsList) {
			List cannotDeleteWorkflowNodeMapList = new ArrayList();
			List<Long> cannotIdsList = new ArrayList<Long>();
			for (Long id : deleteNodeIdsList) {
				Map resultMap = this.findNode(id);
				if (resultMap != null) {
					cannotIdsList.add(Long.valueOf(resultMap
							.get("WORKFLOW_NODE_ID").toString()));
					cannotDeleteWorkflowNodeMapList.add(resultMap);
				}
			}
			deleteNodeIdsList.removeAll(cannotIdsList);
			workflowNodeDao.remove(deleteNodeIdsList);
			return cannotDeleteWorkflowNodeMapList;
		}


	public String isWorkflowUsed(Long workflowId) {
		QueryAssistantSQL sqlAssistant = baseDao
		.newQueryAssistantSQL(" SELECT C.NAME " +
				" FROM wf_workflow_node_instance a, " +
				"     wf_workflow_instance b,wf_workflow c " +
				" WHERE 1 = 1 " +
				" and   b.workflow_id=c.workflow_id "+
				" AND   b.workflow_id = "+workflowId.toString()+
				" AND   b.workflow_instance_id = a.workflow_instance_id(+)");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),new HashMap());
		String resultStr=null;
		if(resultList!=null && resultList.size()>0){
			Map resultMap=resultList.get(0);
			resultStr =resultMap.get("NAME").toString();
		}

		return resultStr;
	}


	public List<Map> getNotUseWorkflow() {
		QueryAssistantSQL sqlAssistant = baseDao
		.newQueryAssistantSQL(" SELECT D.WORKFLOW_ID,D.NAME " +
				" FROM wf_workflow d " +
				" WHERE 1 = 1 " +
				" AND   d.workflow_id not in (SELECT DISTINCT c.workflow_id " +
				" FROM wf_workflow_node_instance a, " +
				" wf_workflow_instance b, " +
				" wf_workflow c " +
				" WHERE 1 = 1 " +
				" AND   b.workflow_id = c.workflow_id " +
				" AND   b.workflow_instance_id = a.workflow_instance_id (+)) ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),new HashMap());
		return resultList;
	}
	
	public Workflow getWorkflowByType(String type){
		List<Workflow> list = this.baseDao.getObjectListByConditions("from Workflow w where w.type = ? ", new Object[]{type});
		return list.size() > 0 ? list.get(0) : null;
	}


	public List<Workflow> getWorkflowForInstance() {
		String sql="from Workflow w where w.status='"+WorkflowDataUtils.ENTITY_STATUS_ON+"'";
		return workflowDao.getObjectListByConditions(sql, new Object[]{});
	}
	
	public void workflowCopy(Workflow originalWorkflow,Workflow dimWorkflow) {
		String nameTmp=dimWorkflow.getName();
		String typeTmp=dimWorkflow.getType();
		try {
			BeanUtils.copyProperties(dimWorkflow,originalWorkflow);
		} catch (Exception e) {
			throw new RuntimeException("不能生成新的工作流对象！");
		}
		dimWorkflow.setName(nameTmp);
		dimWorkflow.setType(typeTmp);
		workflowDao.save(dimWorkflow);
		Map<String,String> pathNodesMap=workflowNodeDao.copyWorkflowEntity(originalWorkflow.getWorkflowId(),dimWorkflow.getWorkflowId());
		workflowPathDao.copyWorkflowEntity(originalWorkflow.getWorkflowId(),dimWorkflow.getWorkflowId(),pathNodesMap);
	}
	
	
	public List<Map> getWorkflowNodes(Map queryMap) {

		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.WORKFLOW_NODE_ID , a.WORKFLOW_ID , a.NODE_STAUS , a.CREATE_TIME , a.LAST_UPDATE_TIME , a.NAME , a.TYPE , a.DISPLAY_NAME , " 
						+" (select distinct decode(e.name, null, '系统管理员', e.name) " 
						+" from employee e, WF_WORKFLOW_NODE wwd " 
						+" where wwd.create_user = e.employee_id(+) " 
						+" and wwd.workflow_node_id = a.workflow_node_id) as CREATE_USER,   " 
						+" (select distinct decode(e.name, null, '系统管理员', e.name) "
						+" from employee e, WF_WORKFLOW_NODE wwd " 
						+" where wwd.last_update_user = e.employee_id(+) " 
						+" and wwd.workflow_node_id = a.workflow_node_id) as LAST_UPDATE_USER " 
						+" FROM WF_WORKFLOW_NODE a WHERE 1=1 ")
				.addCondition(" and WORKFLOW_NODE_ID = :workflowNodeId ")
				.addCondition(" and WORKFLOW_ID = :workflowId ")
				.addCondition(" and NODE_STAUS like :nodeStaus ")
				.addCondition(" and CREATE_USER = :createUser ")
				.addCondition(
						" and CREATE_TIME = to_date(:createTime ,'yyyy-MM-dd') ")
				.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
				.addCondition(
						" and LAST_UPDATE_TIME = to_date(:lastUpdateTime ,'yyyy-MM-dd') ")
				.addCondition(" and NAME like :name ").addCondition(
						" and TYPE like :type ").addCondition(
						" and DISPLAY_NAME like :displayName ").addCondition(
						" and OWNER like :owner ");
				sqlAssistant.setTail(" ORDER BY a.WORKFLOW_NODE_ID DESC ");

		List<Map> resultList = sqlAssistant.query(
				baseDao.getConnection(), queryMap);

		return resultList;
	}
	
	public List<Map> getWorkflowInstanceByPage(Map queryMap, PageRender pageRender){

		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.WORKFLOW_INSTANCE_ID , a.WORKFLOW_ID , a.name W_NAME, a.WORKFLOW_NODE_ID ,  a.STATUS , " +
				"       b.NAME WORKFLOW_NAME, c.name NODE_NAME, c.display_name NODE_DISPLAY_NAME " +
				" FROM WF_WORKFLOW_INSTANCE a , wf_workflow b,  wf_workflow_node c " +
				" WHERE 1=1  " +
				"   and a.workflow_id =b.workflow_id " +
				"   and a.workflow_node_id = c.workflow_node_id ")
    			.addCondition(" and a.WORKFLOW_INSTANCE_ID = :workflowInstanceId ")
    			.addCondition(" and a.WORKFLOW_ID = :workflowId ")					    			
    			.addCondition(" and a.OWNER = :owner ")
    			.addCondition(" and a.STATUS = :status ");
		sqlAssistant.setTail(" ORDER BY a.WORKFLOW_INSTANCE_ID DESC ");
		
		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
	
	
	public void createWorkflowInstance(WorkflowInstance workflowInstance) {
		if (workflowInstance == null
				|| workflowInstance.getWorkflowId() == null)
			throw new RuntimeException("工作流ID必须设置，不可以为空");
		
		
		//这个字段是否有存在必要?
		workflowInstance.setOwner(getNextNodeOperator());
		
		//创建一个新的工作流实例
		workflowInstanceDao.save(workflowInstance);
		
		
		Worklist handlerJob = new Worklist();
		handlerJob.setWorkflowNodeInstanceId(workflowInstance.getWorkflowInstanceId());
		handlerJob.setStatus("END");
		handlerJob.setHandlers(workflowInstance.getCreateUser().toString());
		this.worklistDao.save(handlerJob);
		
		//将保存全局变量的map中数据保存至数据库
		//this.workflowContextService.saveParamsToDb(paramMap, workflowInstance.getWorkflowInstanceId());
		
		//获取第一个节点
		WorkflowNode node = this.getFirstNode(workflowInstance.getWorkflowId());
		
		
		//创建节点实例
		WorkflowNodeInstance workflowNodeInstance = new WorkflowNodeInstance();
		workflowNodeInstance.setWorkflowNodeId(node.getWorkflowNodeId());
		workflowNodeInstance.setWorkflowInstanceId(workflowInstance
				.getWorkflowInstanceId());

		this.workflowNodeInstanceDao.save(workflowNodeInstance);
		
		//更新工作流实例当前节点
		workflowInstance.setWorkflowNodeId(workflowNodeInstance.getWorkflowNodeId());
		workflowInstanceDao.update(workflowInstance);
		
		//走到下一个结点(即开始工作流实例后不要停留在开始结点  自动走到开始结点的下一个结点)
		//instanceNext(workflowInstance, "AUDIT_YES" , null);
	}
	
	private WorkflowNode getFirstNode(Long workflowId) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL("select (select wp.node_to from wf_workflow_path wp where wp.node_from = wn.workflow_node_id) as NODE_ID "
						+ "   from wf_workflow_node wn "
						+ "  where wn.workflow_id = "
						+ workflowId.toString()
						+ " and wn.type = 'start' ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				new HashMap());
		return workflowNodeDao.get(((BigDecimal) resultList.get(0).get("NODE_ID")).longValue());

	}
	
	public List<Map> getFromNodeList(Long workflowNodeId) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL("SELECT p.workflow_path_id, p.name as path_name, p.display_name as path_display_name, " +
						"       n.name as node_name, n.display_name as node_display_name" +
						"  FROM wf_workflow_path p, wf_workflow_node n" +
						" where p.node_from = n.workflow_node_id" +
						"   and p.node_to = " + workflowNodeId.toString()+
						" order by n.name ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				new HashMap());
		return resultList;

	}
	
	public List<Map> getNextNodeList(Long workflowNodeId) {
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL("SELECT p.workflow_path_id, p.name as path_name, p.display_name as path_display_name, " +
						"        n.workflow_node_id, n.name as node_name, n.display_name as node_display_name" +
						"  FROM wf_workflow_path p, wf_workflow_node n" +
						" where p.node_to = n.workflow_node_id" +
						"   and p.node_from = " + workflowNodeId.toString()+
						" order by n.name ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				new HashMap());
		return resultList;

	}
	
	
	
	
	protected Long getNextNodeOperator() {
		return WorkflowDataUtils.DEFAULT_OWNER;
	}

	
	protected WorkflowNode getNextNode(WorkflowNodeInstance nowNode,
			String displayname) {
		WorkflowInstance workflowInstance = this.workflowInstanceDao.get(nowNode.getWorkflowInstanceId());
		WorkflowNodeInstance workflowNodeInstance = this.workflowNodeInstanceDao.get( workflowInstance.getWorkflowNodeId());
		
		List<Long> nextNodeIds = this.workflowPathDao.getNextNode(workflowInstance
				.getWorkflowId(), workflowNodeInstance.getWorkflowNodeId() , displayname);
		
		if(nextNodeIds.isEmpty()) return null;
		
		WorkflowNode nextNode = this.workflowNodeDao.get(nextNodeIds.get(0));
		
		return nextNode;
		
		
	}
	
	public List<Map> getNodeInstanceList(Long workflowInstanceId) {

		String sql = "SELECT a.WORKFLOW_NODE_ID , a.WORKFLOW_INSTANCE_ID ,  " +
				" b.name WORKFLOW_NODE_NAME  " +
				"		 from wf_workflow_node_instance a , wf_workflow_node b   " +
				"		 where  a.workflow_node_id=b.workflow_node_id   " +
				"		 and a.workflow_instance_id ="+workflowInstanceId.toString();
		List<Map> resultList = this.baseDao.query(sql, new HashMap());

		return resultList;
	}
	public List<Map> getParticipantsByNode(Long workflowNodeId) {
		Map queryMap = new HashMap();
		queryMap.put("workflowNodeId", workflowNodeId.toString());
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.PARTICIPANTS_ID , a.PARTICIPANT_TYPE , a.PARTICIPANT_VALUE , a.WORKFLOW_NODE_ID , a.PARTICIPANT_NAME FROM WF_PARTICIPANTS a WHERE 1=1 ")
				.addCondition(" and a.WORKFLOW_NODE_ID = :workflowNodeId ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				queryMap);

		return resultList;
	}
	
	public void saveInstanceToNext(Long workflowInstanceId, Long workflowNodeId) {
		try {
			WorkflowInstance workflowInstance = workflowInstanceDao
					.get(workflowInstanceId);
			WorkflowNode nextNode = workflowNodeDao.get(workflowNodeId);
			List partList = getParticipantsByNode(workflowInstance.getWorkflowNodeId());
			log.error("size==="+partList.size());
			// 如果下一个结点是结束结点,工作流实例结束
			if (nextNode.getType().equals(WorkflowDataUtils.NODE_TYPE_END)) {
				workflowInstance.setStatus(WorkflowDataUtils.WORK_STATUS_END);
			}
			workflowInstance.setWorkflowNodeId(workflowNodeId);
			workflowInstanceDao.update(workflowInstance);
		
			
			//创建下一个结点的结点实例
			WorkflowNodeInstance workflowNodeInstance = new WorkflowNodeInstance();
			workflowNodeInstance.setWorkflowNodeId(workflowNodeId);
			workflowNodeInstance.setWorkflowInstanceId(workflowInstanceId);
			
			workflowNodeInstanceDao.save(workflowNodeInstance);	
			//创建工作历史记录
			Map paramMap = new HashMap();
			paramMap.put("VALUE_01","1");
			paramMap.put("VALUE_02","2");
			paramMap.put("VALUE_03","3");
			paramMap.put("VALUE_04","4");
			paramMap.put("VALUE_05","5");
			log.error("NodeInstanceId="+workflowNodeInstance.getNodeInstanceId());
			workHistoryDao.addHistory(workflowNodeInstance.getNodeInstanceId(),partList,paramMap);		
			} catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	
	
	public WorkflowInstanceDao getWorkflowInstanceDao() {
		return workflowInstanceDao;
	}


	public void setWorkflowInstanceDao(WorkflowInstanceDao workflowInstanceDao) {
		this.workflowInstanceDao = workflowInstanceDao;
	}


	public WorkflowNodeInstanceDao getWorkflowNodeInstanceDao() {
		return workflowNodeInstanceDao;
	}


	public void setWorkflowNodeInstanceDao(
			WorkflowNodeInstanceDao workflowNodeInstanceDao) {
		this.workflowNodeInstanceDao = workflowNodeInstanceDao;
	}


	public WorkflowDao getWorkflowDao() {
		return workflowDao;
	}


	public WorkflowPathDao getWorkflowPathDao() {
		return workflowPathDao;
	}


	public void setWorkflowPathDao(WorkflowPathDao workflowPathDao) {
		this.workflowPathDao = workflowPathDao;
	}


	public WorkflowNodeDao getWorkflowNodeDao() {
		return workflowNodeDao;
	}


	public void setWorkflowNodeDao(WorkflowNodeDao workflowNodeDao) {
		this.workflowNodeDao = workflowNodeDao;
	}


	public void setWorkflowDao(WorkflowDao workflowDao) {
		  this.workflowDao = workflowDao;
	  }


	  public Workflow getWorkflow(Long id){
	      return workflowDao.get(id);
	  }

    public List<Workflow> getAllWorkflow(){
        return workflowDao.getAll();
    }

	public WorklistDao getWorklistDao() {
		return worklistDao;
	}

	public void setWorklistDao(WorklistDao worklistDao) {
		this.worklistDao = worklistDao;
	}

	public WorkHistoryDao getWorkHistoryDao() {
		return workHistoryDao;
	}

	public void setWorkHistoryDao(WorkHistoryDao workHistoryDao) {
		this.workHistoryDao = workHistoryDao;
	}

}